#if (FEATURE_MODE == 0)
/**
 @file ctc_at_oam.c

 @date 2010-3-9

 @version v2.0

  This file contains  OAM (Ethernet OAM/MPLS OAM/PBX OAM and EFM OAM) associated APIs's implementation
*/

/****************************************************************************
 *
* Header Files
*
****************************************************************************/
#include "sal.h"
#include "ctc_oam.h"
#include "ctc_error.h"
#include "ctc_at_oam.h"
#include "sys_usw_oam.h"
#include "sys_usw_common.h"
#include "sys_usw_npm.h"

/****************************************************************************
 *
* Defines and Macros
*
*****************************************************************************/

/****************************************************************************
 *
* Global and Declaration
*
*****************************************************************************/

/****************************************************************************
 *
* Function
*
*****************************************************************************/
int32
ctc_at_oam_add_maid(uint8 lchip, ctc_oam_maid_t* p_maid)
{
    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    return sys_usw_oam_add_maid(SYS_PP_BASE(lchip)+(MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM)?p_maid->pp_id:0), p_maid);
}

int32
ctc_at_oam_remove_maid(uint8 lchip, ctc_oam_maid_t* p_maid)
{
    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    return sys_usw_oam_remove_maid(SYS_PP_BASE(lchip)+(MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM)?p_maid->pp_id:0), p_maid);
}

int32
ctc_at_oam_add_lmep(uint8 lchip, ctc_oam_lmep_t* p_lmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_lmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_lmep->key.pp_bmp);

    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_add_lmep(SYS_PP_BASE(lchip), p_lmep);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_lmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_add_lmep(SYS_CORE_PP_BASE(lchip), p_lmep));
    }

    return ret;

}

int32
ctc_at_oam_remove_lmep(uint8 lchip, ctc_oam_lmep_t* p_lmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    p_lmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_lmep->key.pp_bmp);
    
    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_remove_lmep(SYS_PP_BASE(lchip), p_lmep);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_lmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_remove_lmep(SYS_CORE_PP_BASE(lchip), p_lmep));
    }

    return ret;
}

int32
ctc_at_oam_update_lmep(uint8 lchip, ctc_oam_update_t* p_lmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_lmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_lmep->key.pp_bmp);

    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_update_lmep(SYS_PP_BASE(lchip), p_lmep);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_lmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_update_lmep(SYS_CORE_PP_BASE(lchip), p_lmep));
    }

    return ret;
}

int32
ctc_at_oam_add_rmep(uint8 lchip, ctc_oam_rmep_t* p_rmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_rmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_rmep->key.pp_bmp);

    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
     {
         return sys_usw_oam_add_rmep(SYS_PP_BASE(lchip), p_rmep);
     }
    
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_rmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_add_rmep(SYS_CORE_PP_BASE(lchip), p_rmep));
    }

    return ret;
}

int32
ctc_at_oam_remove_rmep(uint8 lchip, ctc_oam_rmep_t* p_rmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;


    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_rmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_rmep->key.pp_bmp);

    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_remove_rmep(SYS_PP_BASE(lchip), p_rmep);
    }
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_rmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_remove_rmep(SYS_CORE_PP_BASE(lchip), p_rmep));
    }

    return ret;
}

int32
ctc_at_oam_update_rmep(uint8 lchip, ctc_oam_update_t* p_rmep)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;


    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_rmep->key.pp_bmp = SYS_PP_BMP_MAPPING(p_rmep->key.pp_bmp);

    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_update_rmep(SYS_PP_BASE(lchip), p_rmep);
    }
    
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_rmep->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_update_rmep(SYS_CORE_PP_BASE(lchip), p_rmep));
    }

    return ret;
}

int32
ctc_at_oam_add_mip(uint8 lchip, ctc_oam_mip_t* p_mip)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_mip->key.pp_bmp = SYS_PP_BMP_MAPPING(p_mip->key.pp_bmp);

    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_add_mip(SYS_PP_BASE(lchip), p_mip);
    }
    
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_mip->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_add_mip(SYS_CORE_PP_BASE(lchip), p_mip));
    }

    return ret;
}

int32
ctc_at_oam_remove_mip(uint8 lchip, ctc_oam_mip_t* p_mip)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;


    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_mip->key.pp_bmp = SYS_PP_BMP_MAPPING(p_mip->key.pp_bmp);

    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_remove_mip(SYS_PP_BASE(lchip), p_mip);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_mip->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_remove_mip(SYS_CORE_PP_BASE(lchip), p_mip));
    }

    return ret;
}

int32
ctc_at_oam_set_property(uint8 lchip, ctc_oam_property_t* p_prop)
{
    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    CTC_PTR_VALID_CHECK(p_prop);
    
    CTC_ERROR_RETURN(sys_usw_oam_set_property(SYS_PP_BASE(lchip), p_prop));

    return CTC_E_NONE;
}

int32
ctc_at_oam_get_defect_info(uint8 lchip, void* p_defect_info)
{
    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    CTC_ERROR_RETURN(sys_usw_oam_get_defect_info(SYS_PP_BASE(lchip) + (MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM)?((ctc_oam_defect_info_t*)p_defect_info)->pp_id:0), p_defect_info));
        
    return CTC_E_NONE;
}

int32
ctc_at_oam_get_mep_info(uint8 lchip, ctc_oam_mep_info_t* p_mep_info)
{
    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);
    CTC_ERROR_RETURN(sys_usw_oam_get_mep_info(SYS_PP_BASE(lchip) + (MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM)?((ctc_oam_defect_info_t*)p_mep_info)->pp_id:0), p_mep_info, 0));
   
    return CTC_E_NONE;
}


int32
ctc_at_oam_get_mep_info_with_key(uint8 lchip, ctc_oam_mep_info_with_key_t* p_mep_info)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_mep_info->key.pp_bmp = SYS_PP_BMP_MAPPING(p_mep_info->key.pp_bmp);

    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_get_mep_info(SYS_PP_BASE(lchip), p_mep_info, 1);
    }
        
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_mep_info->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_get_mep_info(SYS_CORE_PP_BASE(lchip), p_mep_info, 1));
    }

    return ret;
}

int32
ctc_at_oam_get_stats(uint8 lchip, ctc_oam_stats_info_t* p_stat_info)
{
    int32 ret                      = CTC_E_NONE;
    uint8 pp_bmp = 0;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;


    FEATURE_SUPPORT_CHECK(CTC_FEATURE_OAM);
    LCHIP_CHECK(lchip);

    p_stat_info->key.pp_bmp = SYS_PP_BMP_MAPPING(p_stat_info->key.pp_bmp);
    
    if (!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_OAM))
    {
        return sys_usw_oam_get_stats_info(SYS_PP_BASE(lchip), p_stat_info);
    }
    
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_AT_FOREACH_CORE_LCHIP(lchip, p_stat_info->key.pp_bmp, lchip_start,pp_bmp);
        CTC_AT_FOREACH_ERROR_RETURN(ret, sys_usw_oam_get_stats_info(SYS_CORE_PP_BASE(lchip), p_stat_info));
    }

    return ret;
}

int32
ctc_at_oam_init(uint8 lchip, ctc_oam_global_t* p_cfg)
{
    ctc_oam_global_t oam_global;
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    LCHIP_CHECK(lchip);
    if (NULL == p_cfg)
    {
        sal_memset(&oam_global, 0, sizeof(ctc_oam_global_t));

        /*eth oam global param*/
        oam_global.mep_index_alloc_by_sdk       = 1;

        /*TP Y.1731 OAM*/
        oam_global.tp_y1731_ach_chan_type       = 0x8902;
        oam_global.tp_section_oam_based_l3if    = 0;

        oam_global.tp_csf_ach_chan_type = 9;
        oam_global.tp_csf_los = 0x7;
        oam_global.tp_csf_fdi = 0x1;
        oam_global.tp_csf_rdi = 0x2;
        oam_global.tp_csf_clear = 0x0;
        oam_global.maid_len_format = 3;
    }
    else
    {
        sal_memcpy(&oam_global, p_cfg, sizeof(ctc_oam_global_t));
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_ERROR_RETURN(sys_usw_oam_init(lchip, &oam_global));
    }

    return CTC_E_NONE;
}

int32
ctc_at_oam_deinit(uint8 lchip)
{
    uint8 lchip_start              = 0;
    uint8 lchip_end                = 0;

    LCHIP_CHECK(lchip);
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_ERROR_RETURN(sys_usw_oam_deinit(lchip));
    }

    return CTC_E_NONE;
}

#endif

